package vma.nicici.tests;


import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import vma.nicici.chat.api.Api;
import vma.nicici.chat.communication.GetHttpRequest;

public class GetHttpRequestTest extends TestCase {
	private static String API_URL = Api.URL;
	private static String API_KEY = Api.KADEK_KEY;
	private static String LAST_PULL_TIMESTAMP = "-1";
	
	public void testNotLogged() {
		List<NameValuePair> emptyParams = new ArrayList<NameValuePair>();
		GetHttpRequest getReq = new GetHttpRequest(API_URL, emptyParams);
		
		try {
			String result =  getReq.getStringResponse();
			String expectedContains = "\"status\":\"error\"";
			
			assertTrue(result.contains(expectedContains));
		} catch (Throwable t) {
			fail("Exception thrown");
			t.printStackTrace();
		} 
	}
	
	public void testLogged() {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("lastPullTimestamp", LAST_PULL_TIMESTAMP));
		params.add(new BasicNameValuePair("key", API_KEY));
		
		GetHttpRequest getReq = new GetHttpRequest(API_URL, params);
		
		try {
			String result =  getReq.getStringResponse();
			String expectedContains = "\"status\":\"success\"";
			
			assertTrue(result.contains(expectedContains));
		} catch (Throwable t) {
			fail("Exception thrown");
			t.printStackTrace();
		} 
	}
}
